﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="EvaluationFile.aspx.cs" Inherits="EvaluationFile" Title="Raport Verificari Date" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<%@ Register Namespace="NS_Controls" TagPrefix="cc1" %>
<%@ Register Namespace="CustomControlsNS" TagPrefix="cc2" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.ExtendedGridView"
    TagPrefix="ExtGridView" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderContent" runat="Server">
    <link href="../../Styles/themes/fancy/tabs.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/themes/fancy/fancy-blue/fancy-blue.css" rel="stylesheet"
        type="text/css" />
    <asp:UpdatePanel ID="up1" runat="server">
        <ContentTemplate>
            <!-- onload: strSD.focus() -->
            <table width="90%">
				<tr>
					<td>
			            <asp:Literal ID="output" runat="server" />
					</td>
					<td align="right">
                        <asp:UpdateProgress ID="UpdateProgressValoriContractate" runat="server" DisplayAfter="100">
                            <ProgressTemplate>
                                <span class="clsTextBoldYellow">(<% =Resources.GridView.PageLoading %>)</span>
                            </ProgressTemplate>
                        </asp:UpdateProgress>
					</td>
				</tr>
            </table>
            <ajaxToolKit:TabContainer ID="tabContainer" runat="server" CssClass="fancy fancy-blue">
                <ajaxToolKit:TabPanel ID="t1" runat="server" HeaderText="Factori Indicatori">
                    <ContentTemplate>
                        <asp:Panel ID="selectie" runat="server">
                            <h3 class="menu_th">
                                Calcul indicatori pe luna:
                            </h3>
                            <table id="controaleValidare" border="0" width="50%" style="margin: auto">
                                <tr class="tdn">
                                    <td width="25%" align="right">
                                        Luna:&nbsp;
                                    </td>
                                    <td width="25%" align="center">
                                        <asp:DropDownList ID="strMonthVerif" runat="server" DataTextField="MonthName" DataValueField="ID"
                                            CssClass="box" />
                                    </td>
                                    <td width="25%" align="right">
                                        Anul:&nbsp;
                                    </td>
                                    <td width="25%" align="center">
                                        <asp:DropDownList ID="strYearVerif" runat="server" DataTextField="Code" DataValueField="ID"
                                            CssClass="box" />
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="4" align="center">
                                        <cc2:CustomButton ID="viewRaport" runat="server" Text="Raport" OnServerClick="viewRaport_Click"
                                            OnClick="OnClick_btnViewReport();" />
                                        <asp:Button ID="waitForReport" runat="server" Text="&nbsp;&nbsp;&nbsp;...&nbsp;&nbsp;&nbsp;"
                                            Enabled="false" Style="display: none;" />
                                    </td>
                                </tr>
                            </table>
                            <asp:Literal ID="noFactors" runat="server" Visible="false">
								Nu exista niciun factor pentru indicatori in baza de date.
                            </asp:Literal>
                            <h3 class="menu_th">
                                Istoric verificari factori
                            </h3>
                            <asp:DataGrid ID="validatedReports" runat="server" AutoGenerateColumns="false" Width="98%"
                                HeaderStyle-CssClass="tdh" ItemStyle-CssClass="tdn" CellPadding="4" OnItemDataBound="validatedReports_ItemDataBound"
                                OnItemCommand="validatedReports_ItemCommand">
                                <Columns>
                                    <asp:ButtonColumn CommandName="View" HeaderText="Nr.crt." DataTextField="NrCrt" Text="detalii"
                                        ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundColumn HeaderText="Luna" DataField="MonthName" />
                                    <asp:BoundColumn HeaderText="Anul" DataField="Year" />
                                    <asp:BoundColumn HeaderText="Data Executiei" DataField="ExecDate" />
                                    <asp:BoundColumn HeaderText="Utilizator" DataField="UserName" />
                                    <asp:ButtonColumn ButtonType="PushButton" CommandName="Hide" HeaderText="" Text="Invalideaza!"
                                        ItemStyle-HorizontalAlign="Center" />
                                </Columns>
                            </asp:DataGrid>
                            <asp:Literal ID="noValidatedReports" runat="server" Visible="false">
								Nu a fost validat niciun raport.
                            </asp:Literal>
                        </asp:Panel>
                        <asp:Panel ID="valori" runat="server" Visible="false">
                            <h3>
                                Raport factori pentru luna
                                <asp:Literal ID="monthName" runat="server" />
                                anul
                                <asp:Literal ID="yearName" runat="server" />
                                --
                                <asp:Literal ID="validState" runat="server">nevalidat</asp:Literal>
                            </h3>
                            <asp:Literal ID="noReport" runat="server" Visible="false">
							Nu exista niciun raport de verificare a factorilor.
                            </asp:Literal>
                            <asp:DataGrid ID="reportValues" runat="server" AutoGenerateColumns="false" Width="98%"
                                HeaderStyle-CssClass="tdh" ItemStyle-CssClass="tdn" AlternatingRowStyle-CssClass="tdngris8"
                                CellPadding="4" OnItemDataBound="reportValues_ItemDataBound" OnItemCreated="reportValues_ItemCreated">
                                <Columns>
                                    <asp:BoundColumn HeaderText="Nr.crt." DataField="IsCalculated" ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundColumn HeaderText="Denumire" DataField="Name" />
                                    <asp:BoundColumn HeaderText="Valoare calculata" DataField="Result" ItemStyle-HorizontalAlign="Center" />
                                    <asp:TemplateColumn HeaderText="Valoare modificata" ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtNewValue" runat="server" Style="text-align: center" />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                </Columns>
                            </asp:DataGrid>
                            <table id="butoane" border="0" width="50%" style="margin: auto">
                                <tr>
                                    <td>
                                        <cc2:CustomButton ID="validare" runat="server" Text="Valideaza" OnServerClick="validare_Click" />
                                        <asp:Button ID="dummy" runat="server" Style="display: none;" />
                                        <ajaxToolKit:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="dummy"
                                            PopupControlID="pnlPopup" BackgroundCssClass="modalBackground" CancelControlID="keepEditing" />
                                    </td>
                                    <td>
                                        <cc2:CustomButton ID="inapoi" runat="server" Text="Inapoi" OnServerClick="inapoi_Click" />
                                    </td>
                                </tr>
                            </table>
                        </asp:Panel>
                    </ContentTemplate>
                </ajaxToolKit:TabPanel>
                <ajaxToolKit:TabPanel ID="t2" runat="server" HeaderText="Valori Contractate">
                    <ContentTemplate>
                        <div id="headingInfo" class="menu_th">
                            <table>
                                <tr>
                                    <td>
                                        <asp:Label ID="lblTitluValoriContractate" runat="server" CssClass="menu_th1">Vizualizare raport indicatori management</asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <table id="tblFiltering" border="0">
                            <tr class="tdn">
                                <td width="10%" align="right">
                                    Luna start:&nbsp;
                                    <!-- De la data: -->
                                </td>
                                <td width="20%" align="center">
									<asp:TextBox ID="startValDateStr" runat="server" OnTextChanged="dateIntervalChanged" />
									<ajaxToolKit:CalendarExtender ID="startValDate" runat="server" Format="MMM yyyy"
										OnClientHidden="onCalendarHiddenS"  OnClientShown="onCalendarShownS" BehaviorID="startValDate" TargetControlID="startValDateStr" />
                                </td>
                                <td width="10%" align="right">
                                    Luna sfarsit:&nbsp;
                                    <!-- Pana la data: -->
                                </td>
                                <td width="20%" align="center">
									<asp:TextBox ID="endValDateStr" runat="server" OnTextChanged="dateIntervalChanged" />
									<ajaxToolKit:CalendarExtender ID="endValDate" runat="server" Format="MMM yyyy"
										OnClientHidden="onCalendarHiddenE"  OnClientShown="onCalendarShownE" BehaviorID="endValDate" TargetControlID="endValDateStr" />
                                </td>
                                <td width="10%" align="left">
									<cc2:CustomButton ID="btnFilter" runat="server" Text="Filtreaza" OnServerClick="btnFilter_Click" />
                                </td>
                                <td width="30%" align="right" class="tdn">
									<cc2:CustomButton ID="btnSave" runat="server" Text="Salveaza" OnServerClick="btnSave_Click" />
                                </td>
                            </tr>
                        </table>
                        <br />
                        <asp:Panel ID="contracte" runat="server">
                            <cc1:ExtendedGridView runat="server" ID="grContracted" UseDefaultStyle="true" EnableEdit="false"
                                ShowEditLink="true" ShowInsertLink="true" showDeleteButton="true" AutoSave="true" AllowSorting="true"
                                EnableInsert="false" AllowPaging="true" PageSize="20" AutoGenerateColumns="true"
                                DataKeyNames="ID" EnableFilter="true" EnablePageSize="true" EnableExport="false"
                                Width="98%">
                                <Columns>
                                    <asp:TemplateField HeaderText="D">
                                        <ItemTemplate>
                                            <asp:ImageButton runat="server" ID="btnDelete" AlternateText="<%$ Resources:GridView, Delete %>"
                                                ImageUrl="~/Images/Btn/delete.gif" OnClick="imgDelete_Click" OnClientClick='if (!confirm(g_str_CONFIRM_ValidateAnswer)) return false;' />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </cc1:ExtendedGridView>
                        </asp:Panel>
                    </ContentTemplate>
                </ajaxToolKit:TabPanel>
                <ajaxToolKit:TabPanel ID="t3" runat="server" HeaderText="Fisa de evaluare">
                    <ContentTemplate>
                        <table id="timeFrame" border="0">
                            <tr class="tdn">
                                <td width="20%" align="right">
                                    Luna start:&nbsp;
                                </td>
                                <td width="20%" align="center">
                                    <asp:DropDownList ID="strMonthStart" runat="server" DataTextField="MonthName" DataValueField="ID"
                                        AutoPostBack="true" OnSelectedIndexChanged="CheckInterval" CssClass="box" />
                                </td>
                                <td width="20%" align="right">
                                    Luna sfarsit:&nbsp;
                                </td>
                                <td width="20%" align="center">
                                    <asp:DropDownList ID="strMonthEnd" runat="server" DataTextField="MonthName" DataValueField="ID"
                                        AutoPostBack="true" OnSelectedIndexChanged="CheckInterval" CssClass="box" />
                                </td>
                                <td width="10%" align="right">
                                    Anul:&nbsp;
                                </td>
                                <td width="10%" align="center">
                                    <asp:DropDownList ID="strYear" runat="server" DataTextField="Code" DataValueField="ID"
                                        CssClass="box" />
                                </td>
                            </tr>
                            <tr>
                                <td colspan="6" align="center">
                                    <%--cc2:CustomButton ID="btnReport" runat="server" Text="Raport Fisa Vizualizare" OnClick="ShowReport();" /--%>
                                    <asp:Button ID="btnReport" runat="server" Text="Raport Fisa Vizualizare" OnClientClick="ShowReport();" />
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </ajaxToolKit:TabPanel>
            </ajaxToolKit:TabContainer>
            <asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none;">
                <table style="width: 200px">
                    <tr>
                        <td>
                            Factorii au fost salvati.
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Button ID="inapoi2" runat="server" Text="&nbsp;&nbsp;OK&nbsp;&nbsp;" OnClick="inapoi_Click" />
                            <asp:Button ID="keepEditing" runat="server" Text="Modifica" />
                        </td>
                    </tr>
                </table>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
    <script language="javascript" type="text/javascript">
        var g_str_CONFIRM_ValidateAnswer = '<% =Resources.DatabaseStrings.CONFIRM_DeleteReport.ReplaceApostrophe() %>';
        function OnClick_btnViewReport() {
            $get('tbl<% =viewRaport.ClientID %>').style.display = 'none';
            $get('<% =waitForReport.ClientID %>').style.display = 'inline';
            __doPostBack('<% =viewRaport.UniqueID %>_btn', '');
        }

        var g_str_strMonthStart = '<% =strMonthStart.ClientID %>';
        var g_str_strMonthEnd = '<% =strMonthEnd.ClientID %>';
        var g_str_strYear = '<% =strYear.ClientID %>';

        function ShowReport() {
            monthStart = $get(g_str_strMonthStart).options[$get(g_str_strMonthStart).selectedIndex].text;
            monthEnd = $get(g_str_strMonthEnd).options[$get(g_str_strMonthEnd).selectedIndex].text;
            yearDate = $get(g_str_strYear).options[$get(g_str_strYear).selectedIndex].text;
            yearDateI = $get(g_str_strYear).options[$get(g_str_strYear).selectedIndex].value;
            monthStartI = $get(g_str_strMonthStart).selectedIndex + 1;
            monthEndI = $get(g_str_strMonthEnd).selectedIndex + 1;

            var wOpen;
            var sOptions;
            var aWinName = '_blank';
            var aURL = 'ReportIndicatori.aspx?monthStart=' + monthStart + '&monthEnd=' + monthEnd + '&year=' + yearDate + '&monthStartI=' + monthStartI + '&monthEndI=' + monthEndI + '&yearDateI=' + yearDateI;

            sOptions = 'toolbar=0,location=1,status=1,menubar=0,scrollbars=1,resizable=1';
            sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
            sOptions = sOptions + ',height=' + (screen.availHeight - 152).toString();
            sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';
            wOpen = window.open('', aWinName, sOptions);
            wOpen.location = aURL;
        }

        //calendar code thanks to: http://www.aghausman.net/asp/how-to-show-and-select-monthyear-in-calendar-extender.html
        function onCalendarShownS() {
        	var cal = $find("startValDate");
        	cal._switchMode("months", true); //Setting the default mode to month
        	SetHandler(cal);
        }

        function onCalendarShownE() {
        	cal = $find("endValDate");
        	cal._switchMode("months", true); //Setting the default mode to month
        	SetHandler(cal);
        }

        function SetHandler(calendarTarget) {
        	//Iterate every month Item and attach click event to it
        	if (calendarTarget._monthsBody) {
        		for (var i = 0; i < calendarTarget._monthsBody.rows.length; i++) {
        			var row = calendarTarget._monthsBody.rows[i];
        			for (var j = 0; j < row.cells.length; j++) {
        				Sys.UI.DomEvent.addHandler(row.cells[j].firstChild, "click", monthClick);
        			}
        		}
        	}
        }

        function onCalendarHiddenS() {
        	var cal = $find("startValDate");
        	ClearHandler(cal);
        }
        function onCalendarHiddenE() {
        	cal = $find("endValDate");
        	ClearHandler(cal);
        }
        function ClearHandler(calendarTarget) {
        	//Iterate every month Item and remove click event from it
        	if (calendarTarget._monthsBody) {
        		for (var i = 0; i < calendarTarget._monthsBody.rows.length; i++) {
        			var row = calendarTarget._monthsBody.rows[i];
        			for (var j = 0; j < row.cells.length; j++) {
        				Sys.UI.DomEvent.removeHandler(row.cells[j].firstChild, "click", monthClick);
        			}
        		}
        	}
        }

        function monthClick(eventElement) {
        	var target = eventElement.target;
        	switch (target.mode) {
        		case "month":
        			var targetId = target.id.substring(0, target.id.indexOf('_'));
        			//alert(targetId);
        			var calendarTarget = $find(targetId);
        			//alert(calendarTarget.id);
        			calendarTarget._visibleDate = target.date;
        			calendarTarget.set_selectedDate(target.date);
        			calendarTarget._switchMonth(target.date);
        			calendarTarget._blur.post(true);
        			calendarTarget.raiseDateSelectionChanged();
        			//var textboxTarget = $get(targetId + 'Str'); // NB: == null... :-|
        			break;
        	}
        	//alert($find('btnFilter'));
        	$get('ctl00_ContentPlaceHolderContent_tabContainer_t2_btnFilter_btn').click();
        }

    </script>
</asp:Content>
